package com.dwxt.community.admin.controller;

import com.dwxt.common.base.*;
import com.dwxt.community.entity.*;
import com.dwxt.community.service.*;
import org.apache.commons.lang.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;

import javax.validation.*;

/**
 * 资讯 后台管理
 *
 * @author shenwenkang
 */
@RestController
@RequestMapping("/cms/admin/information")
public class InformationControllerAdmin {

    @Autowired
    private InformationService informationService;

    /**
     * showdoc
     * @catalog 社区后台管理/资讯
     * @title 获取资讯列表
     * @description 获取资讯列表
     * @method get
     * @url /cms/admin/information/get
     * @param pageNum         非必须 Integer 当前页
     * @param pageSize        非必须 Integer 条数
     * @param type            非必须 String 资讯类型
     * @param name            非必须 String 搜索 关键词 根据资讯标题模糊查询
     * @param release         非必须 Integer 是否发布 1：发布 0未发布
     * @param recommend       非必须 Integer 是否推荐 1：推荐 0不推荐
     * @param isNotAdLocation 非必须 Boolean 是否已经绑定页面显示的位置  true：返回没有绑定位置的资讯
     * @return {"status":200,"msg":"SUCCESS","data":{"total":7,"list":[{"id":"6","title":"【社区】重庆尚有无症状感染者11例正在接受医学观察其中境外输入4例","cover":"http://125.62.47.82/upload/2.jpg","video":"http://125.62.47.82/upload/xxx.mp4","auther":"dwxt","release":1,"boutique":0,"createTime":"2020-04-0119:20:43","updateTime":"2020-04-1007:43:47","adTypeId":2,"hits":3,"star":0,"releaseTime":"2020-04-0906:23:25","adLocationId":"4","recommend":0,"priority":5,"starIs":false,"adType":{"id":"2","name":"社区","createTime":1585852236000,"updateTime":1585588152000,"description":"社区"}}],"pageNum":1,"pageSize":10,"size":7,"startRow":1,"endRow":7,"pages":1,"prePage":0,"nextPage":0,"isFirstPage":true,"isLastPage":true,"hasPreviousPage":false,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[1],"navigateFirstPage":1,"navigateLastPage":1}}
     */
    @GetMapping("/get")
    public BaseResult get(@RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "10") Integer pageSize,
                          String type,
                          String name,
                          Integer release,
                          boolean isNotAdLocation,
                          Integer recommend) {
        return informationService.get(pageNum, pageSize, type, name, release, isNotAdLocation, recommend);
    }

    /**
     * showdoc
     * @catalog 社区后台管理/资讯
     * @title 清除资讯位置
     * @method get
     * @description 清除资讯位置
     * @url /cms/admin/information/delLocation
     * @param id 必须 String 资讯ID
     * @return {"status":200,"msg":"SUCCESS","data":null}
     */
    @RequestMapping("/delLocation")
    public BaseResult delLocation(String id) {
        return informationService.delLocation(id);
    }

    /**
     * showdoc
     * @param pageNum  非必须 Integer 当前页
     * @param pageSize 非必须 Integer 每页条数
     * @return {"status":200,"msg":"SUCCESS","data":[{"id":"4","name":"广告位","informationVo":{"id":"6","title":"【社区】重庆尚有无症状感染者11例正在接受医学观察其中境外输入4例","cover":"http://125.62.47.82/upload/2.jpg","auther":"dwxt","hits":3,"star":2,"releaseTime":"2020-04-0906:23:25","starIs":false}}]}
     * @catalog 社区后台管理/资讯
     * @title 获取页面显示位置对应的资讯
     * @method get
     * @description 获取页面显示位置对应的资讯
     * @url /cms/admin/information/getByLocation
     */
    @GetMapping("/getByLocation")
    public BaseResult getByLocation(@RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer pageSize) {
        return informationService.getByLocation(pageNum, pageSize);
    }


    /**
     * showdoc
     * @param title 必须 String 资讯标题
     * @param cover 必须 String 封面路径
     * @param release 必须 Integer 是否发布 1.发布 0.不发布
     * @param recommend 必须 Integer 是否推荐 1.推荐 0.不推荐
     * @param priority 必须 Integer 优先级
     * @param description 必须 String 资讯描述
     * @param content 必须 String 资讯内容
     * @return {"status":200,"msg":"SUCCESS","data":null}
     * @catalog 社区后台管理/资讯
     * @title 添加资讯
     * @method post
     * @description 添加资讯
     * @url /cms/admin/information/insert
     */
    @PostMapping("/insert")
    public BaseResult insert(@Valid InformationWithBLOBs information) {
        if (information.getAdTypeId() == null){
            return BaseResult.build(StatusCode.INFORMATION_NOT_SET_TYPE);
        }
        return informationService.insert(information);

    }

    /**
     * showdoc
     * @param id String 资讯ID
     * @return {"status":200,"msg":"SUCCESS","data":null}
     * @catalog 社区后台管理/资讯
     * @title 发布或者撤下资讯
     * @method post
     * @description 发布或者撤下资讯
     * @url /cms/admin/information/release
     * @remark
     * @Author shenwenkang
     * @Date 2020/4/13
     */
    @PostMapping("/release")
    public BaseResult release(String id) {
        return informationService.release(id);
    }

    /**
     * showdoc
     * @param id String 资讯ID
     * @return {"status":200,"msg":"SUCCESS","data":null}
     * @catalog 社区后台管理/资讯
     * @title 删除资讯
     * @method delete
     * @description 删除资讯，物理删除
     * @url /cms/admin/information/del
     * @remark
     * @Author shenwenkang
     * @Date 2020/4/13
     */
    @RequestMapping("/del")
    public BaseResult del(String id) {
        if (StringUtils.isBlank(id)) {
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return informationService.del(id);
    }

    /**
     * showdoc
     * @param id 必须 String 资讯ID
     * @param title 必须 String 资讯标题
     * @param cover 必须 String 封面路径
     * @param release 必须 Integer 是否发布
     * @param recommend 必须 Integer 是否推荐
     * @param priority 必须 Integer 优先级
     * @param description 必须 String 资讯描述
     * @param content 必须 String 资讯内容
     * @return {"status":200,"msg":"SUCCESS","data":null}
     * @catalog 社区后台管理/资讯
     * @title 修改资讯
     * @method post
     * @description 修改资讯
     * @url /cms/admin/information/update
     */
    @PostMapping("/update")
    public BaseResult update(@Valid InformationWithBLOBs information) {
        String id = information.getId();
        if (id == null) {
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return informationService.update(information);
    }
}
